local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.Server_PlayerComponent(),script.Parent.Name);
local ItemTool=_G.CommonOHOH.load.ItemTool();

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.DataBase=self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent())
	self.data=self.DataBase:GetData("set_data")
    
    self.ItemCtrl=self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl())
	self.redeemData=self.DataBase:GetData("redeem")
end;


function M.Set(self,key,v)
	if not self.data[key] then
		return false
	end
	
	self.DataBase:Execut(function()
		if self.data[key]==0 then
			self.data[key]=1
		else
			self.data[key]=0
		end
	end);

	return true
end

local redeem_cfg =require(game.ServerScriptService.Config.redeem);

function M.Exchange(self,code)

	if self.redeemData[code] then
		return nil
	end

	local reward=redeem_cfg.GetReward(code,self.DataBase:GetData("base"))

	local add={}
	if reward then
		self.redeemData[code]=true
		for k,v in pairs(reward) do
			local key,count= ItemTool.GetRewardByLevel(k,v,self.DataBase:GetData("base").level)
			add[key]=count
			self.ItemCtrl:AddAnyThing(key,count)
		end
	end
	
	return add
end


function M.dtor(self)
	M.super.dtor(self);
end;

local function_list = _G.ServerOHOH.function_list

M:RegistFunction(function_list.set_change,M.Set)
M:RegistFunction(function_list.code_exchange,M.Exchange)




return M